/**
 * 添加或者修改页面
 */

layui.use(['form', 'admin', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload; //得到 upload 对象
    var layer = layui.layer;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //选完文件后不自动上传
    $('#test9').click(function () {

        var  index = layer.msg('文件处理中。。。请耐心等待', {
            icon: 16,
            shade: [0.2,'#000'], //0.1透明度的白色背景
            time: false
        });
        var formdata = new FormData();
        formdata.append('file', document.getElementById("test8").files[0]);
        formdata.append('putCustomerId', $("#putCustomerId").val());
        formdata.append('warehouseId', $("#warehouseId").val());
        formdata.append('settlement', $("#settlement").val());
        $.ajax({
            type: 'Post',
            data:formdata,
            cache: false,//上传文件无需缓存
            processData:false, //告诉jQuery不要去处理发送的数据
            contentType:false,
            url: Feng.ctxPath + "/expressDeliveryWaybill/importExpressDeliveryWaybill",
            success: function (data) {
                layer.close(index);
                if(data.success){
                    if (data.message != null &&data.message != "" ) {
                        var msg =  layer.open({
                            title: '提示' ,
                            content: data.message,
                            btn: ['确定'],
                            yes: function (){
                                layer.close(msg);
                                var Indexs = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(Indexs);
                            }
                        });
                    } else {
                        Feng.success("导入成功！"+data.message);
                        var Indexs = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(Indexs);
                    }
                }else{
                    if (data.message !=null &&data.message!='') {
                        var msg =  layer.open({
                            title: '提示' ,
                            content: data.message,
                            btn: ['确定'],
                            yes: function (){
                                layer.close(msg);
                            }
                        });
                    } else {
                        Feng.error("导入失败！");
                    }
                }
            },
            error: function(data){
                layer.close(index);
                Feng.error("网络异常，请稍后重试！" + data.responseJSON.message)
            }
        });
    });

    //返回按钮
    $("#backupPage").click(function () {
        var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });

    $(".a-upload").on("change","input[type='file']",function(){
        $(".showFileName").html("");
        var filePath=$(this).val();
        if(filePath.indexOf("xls")!=-1 || filePath.indexOf("xlsx")!=-1){
            var arr=filePath.split('\\');
            var fileName=arr[arr.length-1];
            $(".showFileName").html(fileName);
        }else{
            $(".showFileName").html("您未上传文件，或者您上传文件类型有误！");
            return false
        }
    })

});